attribute vec4 vPosition;
attribute vec2 a_texcoord;
attribute vec4 a_color;
attribute vec3 vNormal;
varying vec2 v_texcoord;
varying vec4 v_color;
varying vec3 normal;
//varying vec4 position;
varying vec3 lightDirection;
varying float attenuation;
varying vec3 halfVector;

uniform mat4 matrix;
uniform mat3 normalMatrix;//use to change normal
//uniform mat4 mvMatrix; // matrix before perspectivity

uniform vec3 lightPosition;
uniform vec3 eyeDirection;
uniform float constantAttenuation;
uniform float linearAttenuation;
uniform float quadraticAttenuation;

void main(){
    v_texcoord = a_texcoord;
    v_color = a_color;

    normal = vNormal;//normalize(normalMatrix * vNormal);

    lightDirection = lightPosition - vec3(vPosition);

    float lightDis = length(lightDirection);

    lightDirection = lightDirection/lightDis;

    attenuation = 1.0/(constantAttenuation + linearAttenuation * lightDis + quadraticAttenuation * lightDis * lightDis);
    halfVector = normalize(lightDirection + eyeDirection);

    gl_Position = matrix * vPosition;
}
